package cn.source.web.controller.subject;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.enums.BusinessType;
import cn.source.subject.domain.SmSubject;
import cn.source.subject.service.ISmSubjectService;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.common.core.page.TableDataInfo;

/**
 * 选科与专业组合Controller
 *
 * @author xuhao
 * @date 2023-12-22
 */
@RestController
@RequestMapping("/subject/subject")
public class SmSubjectController extends BaseController
{
    @Autowired
    private ISmSubjectService smSubjectService;

    /**
     * 查询选科与专业组合列表
     */
    @PreAuthorize("@ss.hasPermi('subject:subject:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmSubject smSubject)
    {
        startPage();
        List<SmSubject> list = smSubjectService.selectSmSubjectList(smSubject);
        return getDataTable(list);
    }

    /**
     * 导出选科与专业组合列表
     */
    @PreAuthorize("@ss.hasPermi('subject:subject:export')")
    @Log(title = "选科与专业组合", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmSubject smSubject)
    {
        List<SmSubject> list = smSubjectService.selectSmSubjectList(smSubject);
        ExcelUtil<SmSubject> util = new ExcelUtil<SmSubject>(SmSubject.class);
        util.exportExcel(response, list, "选科与专业组合数据");
    }

    /**
     * 获取选科与专业组合详细信息
     */
    @PreAuthorize("@ss.hasPermi('subject:subject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(smSubjectService.selectSmSubjectById(id));
    }

    /**
     * 新增选科与专业组合
     */
    @PreAuthorize("@ss.hasPermi('subject:subject:add')")
    @Log(title = "选科与专业组合", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmSubject smSubject)
    {
        return toAjax(smSubjectService.insertSmSubject(smSubject));
    }

    /**
     * 修改选科与专业组合
     */
    @PreAuthorize("@ss.hasPermi('subject:subject:edit')")
    @Log(title = "选科与专业组合", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmSubject smSubject)
    {
        return toAjax(smSubjectService.updateSmSubject(smSubject));
    }

    /**
     * 删除选科与专业组合
     */
    @PreAuthorize("@ss.hasPermi('subject:subject:remove')")
    @Log(title = "选科与专业组合", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smSubjectService.deleteSmSubjectByIds(ids));
    }
}
